<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/8/4
 * Time: 5:31 PM
 */
namespace app\frontend\modules\site\controllers;

use app\common\models\Theme;
use app\common\models\ThemeFile;
use app\common\services\theme\ThemeService;
use app\frontend\modules\site\services\PageService;
use app\frontend\modules\site\services\SiteBaseService;

class PageController extends SiteBaseController
{
    public function index(){
        $id = request()->id;
        $themeService = new ThemeService();
        $themeInfo = $themeService->getDefaultThemeInfo($this->clientType,ThemeFile::TYPE_PAGE);
        $themeFileInfo = $themeInfo['themeFiles'][0];
        $pageData = $themeService->pageData($themeFileInfo);
        $datas = $pageData['datas'];
        $pageService = new PageService();
        $pageDetail = $pageService->getDetail($id);
        $pageInfo = $pageDetail['info'];
        $siteInfo = (new SiteBaseService())->siteInfo();
        $siteInfo = $pageService->fmtSeoInfo($siteInfo,$pageInfo);
        $view = $themeFileInfo['file'];
        $view = $pageService->getView($this->clientType,$view,$pageInfo);
        $view = $themeInfo['theme'].'.'.$view;
        return view($view, [
            'site_info'=>$siteInfo,
            'page_info'=>$pageInfo,
            'vars' =>$datas
        ]);

    }
}